package com.zx.cloud.order.service.impl;

import com.zx.cloud.order.mapper.OrderTblMapper;
import com.zx.cloud.order.model.OrderTbl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;

import io.seata.core.context.RootContext;
import lombok.extern.slf4j.Slf4j;

/**
 * @author zhaoxuan
 * @date 2021-12-22 17:56
 **/
@Service
@Slf4j
public class OrderImpl {
    @Autowired
    private OrderTblMapper orderTblMapper;

    @Transactional(rollbackFor = Exception.class)
    public void createOrder(String userId, String commodityCode, Integer count){
        BigDecimal orderMoney = new BigDecimal(count).multiply(new BigDecimal(5));
        OrderTbl order = new OrderTbl().setUserId(userId).setCommodityCode(commodityCode).setCount(count).setMoney(
                orderMoney);
        orderTblMapper.insert(order);
    }
}
